import { clsx, type ClassValue } from 'clsx';
import { customAlphabet } from 'nanoid';
import { twMerge } from 'tailwind-merge';

// 合并className
export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}

// 首字母转大写
export function capitalize(str: string) {
  if (!str || typeof str !== 'string') return str;
  return str.charAt(0).toUpperCase() + str.slice(1);
}
// 脱敏手机号
export function hidePhoneNumber(phone: string) {
  return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
}
// 生成随机长度的字符
export const generateCode = (len = 10) => {
  const only_alpha =
    'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';

  const nano = customAlphabet(only_alpha, len);
  return nano();
};

